<?php

namespace teach\service;

//use teach\components\WeChat;
use Yii;

class SendWechatMessage
{
    /**
     * 商品被买通知
     * @param $openid
     * @param $formid
     * @param $amount
     * @param $name
     * @param $phone
     * @param $address
     * @return mixed
     */
    public function wasBuy($openid, $formid, $amount, $name, $phone, $address)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "8zMj8TST2CWLlH6-K4DoTAgf_vlCpEnwUVHUhreGIpc",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
                "keyword2" => [
                    "value" => $name,
                ],
                "keyword3" => [
                    "value" => $amount,
                ],
                "keyword4" => [
                    "value" => $phone,
                ],
                "keyword5" => [
                    "value" => $address,
                ],
            ],
        ];

//        $WeChat = new WeChat();
//        return $WeChat->sendMsg($msg);
    }

    /**
     * 下单用户小程序通知
     * @param $openid
     * @param $formid
     * @param $out_trade_no
     * @param $amount
     * @param $name
     * @param $phone
     * @param $address
     * @return mixed
     */
    public function buy($openid, $formid, $out_trade_no, $amount, $name, $phone, $address)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "LajDR1ZqgCjund8KTZnFdIfsgdcE2VSKyvGB-eu8Kq8",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
                "keyword2" => [
                    "value" => strval($out_trade_no),
                ],
                "keyword3" => [
                    "value" => $amount,
                ],
                "keyword4" => [
                    "value" => $name,
                ],
                "keyword5" => [
                    "value" => $phone,
                ],
                "keyword6" => [
                    "value" => $address,
                ],
            ],
        ];

//        $WeChat = new WeChat();
//        return $WeChat->sendMsg($msg);
    }

    //订阅消息 用户购买成功通知
    public function buys($openid, $out_trade_no, $amount, $name, $phone, $address)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "a8ZYQDLIRrEKMqa0cqraVwOyA58P3g0g1vthLyW6ZjY",
            "page" => "shopPage/shoppages/index/index",
            "data" => [
                "character_string1" => [
                    "value" => $out_trade_no,
                ],
                "amount2" => [
                    "value" => $amount,
                ],
                "thing3" => [
                    "value" => $name,
                ],
                "phone_number4" => [
                    "value" => $phone,
                ],
                "thing5" => [
                    "value" => $address,
                ],
            ],
        ];
    }

    /**
     * 商家发货给商家以及用户小程序通知
     * @param $openid
     * @param $formid
     * @param $out_trade_no
     * @param $name
     * @param $phone
     * @param $logistics
     * @param $order_num
     * @param $tip
     * @return mixed
     */
    public function deliver($openid, $formid, $out_trade_no, $phone, $name, $logistics, $order_num, $tip)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "TmouKUQjgFCkZtHbWD0zrob1k_PDVbMRBnp1Ho4yHEs",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
                "keyword2" => [
                    "value" => strval($out_trade_no),
                ],
                "keyword3" => [
                    "value" => $phone,
                ],
                "keyword4" => [
                    "value" => $name,
                ],
                "keyword5" => [
                    "value" => $logistics,
                ],
                "keyword6" => [
                    "value" => $order_num,
                ],
                "keyword7" => [
                    "value" => $tip,
                ],
            ],
        ];

//        $WeChat = new WeChat();
//        return $WeChat->sendMsg($msg);
    }

    //小程序发送订阅消息给用户发货
    public function delivers($openid, $out_trade_no, $logistics, $order_num)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "vy8vBmkrdxj7bi0MfKFARIvjpAjVXWrVi2-LA6e6iCM",
            "page" => "shopPage/shoppages/index/index",
            "data" => [
                "character_string4" => [
                    "value" => $out_trade_no,
                ],
                "thing5" => [
                    "value" => $logistics, //物流公司
                ],
                "character_string6" => [
                    "value" => $order_num, //物流单号
                ],
            ],
        ];
    }

    /**
     * 给每个用户发送佣金入账的消息
     * @param $openid
     * @param $formid
     * @param $score
     * @param $tip
     * @return mixed
     */
    public function getScore($openid, $formid, $score, $tip)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "BiYTD2_NHlPpfOS2Gw8WXorr5sih-oWhhomgHM1jiFs",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
                "keyword2" => [
                    "value" => strval($score),
                ],
                "keyword3" => [
                    "value" => $tip,
                ],
            ],
        ];

//        $WeChat = new WeChat();
//        return $WeChat->sendMsg($msg);
    }

    //订阅消息给用户入账积分提醒
    public function getScores($openid, $score, $reason, $tip)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "a-XsNJag6v96ed8t5Hive5IFUoYgCjl_iNf_yPCfUlU",
            "page" => "shopPage/shoppages/index/index",
            "data" => [
                "character_string2" => [
                    "value" => $score,//积分
                ],
                "date4" => [
                    "value" => date("Y-m-d H:i", time()),//时间
                ],
                "thing5" => [
                    "value" => $reason,//理由
                ],
                "thing6" => [
                    "value" => $tip,//提示
                ],
            ],
        ];
    }

    /**
     * 收货成功
     * @param $openid
     * @param $formid
     * @param $out_trade_no
     * @param $status
     * @param $order_time
     * @param $send_time
     * @return mixed
     */
    public function receiveGoods($openid, $formid, $out_trade_no, $status, $order_time, $send_time)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "jsbZvstFXKkUIw0stbc9NtgP_0_2cwGNxhI7yW2bUaw",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => $out_trade_no,
                ],
                "keyword2" => [
                    "value" => $status,
                ],
                "keyword3" => [
                    "value" => date("Y-m-d", $order_time),
                ],
                "keyword4" => [
                    "value" => date("Y-m-d", $send_time),
                ],
                "keyword5" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
            ],
        ];
//
//        $WeChat = new WeChat();
//        return $WeChat->sendMsg($msg);
    }

    /**
     * 用户购买时，给上级，上上级发送积分提醒
     * @param $openid
     * @param $formid
     * @param $score //积分
     * @param $reason //获取原因
     * @param $tips //提示:当用户收货时，积分入账
     * @return array
     */
    public function payGoods($openid, $formid, $score, $reason, $tips)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "BiYTD2_NHlPpfOS2Gw8WXusRSqjRZ33byYCZX43GZCA",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => $score,
                ],
                "keyword2" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
                "keyword3" => [
                    "value" => $reason,
                ],
                "keyword4" => [
                    "value" => $tips,
                ],
            ],
        ];
    }

    /**
     * 给开发者发送有错的模板消息
     * @param $openid //用户openid
     * @param $formid //发送消息的模板
     * @param $des //问题描述
     * @param $project_name //项目名字
     * @param $tip //提示
     * @param $address //发生错误的地址
     * @return array
     */
    public function developer($openid, $formid, $des, $project_name, $tip, $address)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "3YnSO8jZUbFhDBSCN14-UQ3Kf_iAXWZKkFgcMfI1Q1U",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [
                    "value" => date("Y-m-d H:i:s", time()),
                ],
                "keyword2" => [
                    "value" => $des,
                ],
                "keyword3" => [
                    "value" => $project_name,
                ],
                "keyword4" => [
                    "value" => $tip,
                ],
                "keyword5" => [
                    "value" => $address,
                ],
            ],
        ];
    }

    /**
     * 给开发者发送有错的模板消息
     * @param $openid //用户openid
     * @param $formid //发送消息的模板
     * @param $des //问题描述
     * @param $project_name //项目名字
     * @param $tip //提示
     * @param $address //发生错误的地址
     * @return array
     */
    public function developerSame($openid, $formid, $des, $project_name, $tip, $address)
    {
        return $msg = [
            "touser" => $openid,
//            "weapp_template_msg" => [
//                "template_id" => "3YnSO8jZUbFhDBSCN14-UQ3Kf_iAXWZKkFgcMfI1Q1U",
//                "page" => "shopPage/shoppages/index/index",
//                "form_id" => $formid,
//                "data" => [
//                    "keyword1" => [
//                        "value" => date("Y-m-d H:i:s", time()),
//                    ],
//                    "keyword2" => [
//                        "value" => $des,
//                    ],
//                    "keyword3" => [
//                        "value" => $project_name,
//                    ],
//                    "keyword4" => [
//                        "value" => $tip,
//                    ],
//                    "keyword5" => [
//                        "value" => $address,
//                    ],
//                ],
//                "emphasis_keyword" => "keyword1.DATA"
//            ],
            "mp_template_msg" => [
                "appid" => Yii::$app->params['serviceNum']['wxAppId'],
                "template_id" => "UJmLKEFRpKqlXtVXrIE0yXg2NoGXAro4_XDTwkrep2c",
                "url" => "http://weixin.qq.com",
                "miniprogram" => [
                    "appid" => Yii::$app->params['mini']['wxAppId'],
                    "pagepath" => "shopPage/shoppages/index/index"
                ],
                "data" => [
                    "first" => [//头部
                        "value" => "线上监控",
                        "color" => "#DC143C"
                    ],
                    "keyword1" => [//规则名称
                        "value" => "监控触发警告",
                    ],
                    "keyword2" => [//触发时间
                        "value" => date("Y-m-d H:i:s", time()),
                    ],
                    "keyword3" => [//设备名称
                        "value" => $project_name,
                    ],
                    "keyword4" => [//子项名称
                        "value" => $address
                    ],
                    "keyword5" => [//当前参数
                        "value" => $tip
                    ],
                    "remark" => [//提示语
                        "value" => $des,
                    ],
                ]
            ]
        ];
    }

    /**
     * 订单状态 | 退款
     * @param $openid
     * @param $out_trade_no
     * @param $status
     * @param $amount
     * @param $remarks
     * @param $product
     * @return array
     */
    public function refundStatus($openid, $formid ,$out_trade_no, $status, $amount, $remarks, $product)
    {
        return $msg = [
            "touser" => $openid,
            "template_id" => "N605uuu1Zfcc5KxrOo09U_UgNmIuZGW5LjBzpvkp2Is",
            "page" => "shopPage/shoppages/index/index",
            "form_id" => $formid,
            "data" => [
                "keyword1" => [//订单编号
                    "value" => $out_trade_no,
                ],
                "keyword2" => [//退款状态
                    "value" => $status,
                ],
                "keyword3" => [//退款金额
                    "value" => $amount,
                ],
                "keyword4" => [// 备注
                    "value" => $remarks,
                ],
                "keyword5" => [//商品详情
                    "value" => $product
                ],
            ],
        ];
        /**
        return $msg = [
            "touser" => $openid,
                        "weapp_template_msg" => [
                "template_id" => "3YnSO8jZUbFhDBSCN14-UQ3Kf_iAXWZKkFgcMfI1Q1U",
                "page" => "shopPage/shoppages/index/index",
                "form_id" => $formid,
                "data" => [
                    "keyword1" => [
                        "value" => date("Y-m-d H:i:s", time()),
                    ],
                    "keyword2" => [
                        "value" => $des,
                    ],
                    "keyword3" => [
                        "value" => $project_name,
                    ],
                    "keyword4" => [
                        "value" => $tip,
                    ],
                    "keyword5" => [
                        "value" => $address,
                    ],
                ],
                "emphasis_keyword" => "keyword1.DATA"
            ],
            "mp_template_msg" => [
                "appid" => Yii::$app->params['serviceNum']['wxAppId'],
                "template_id" => "UJmLKEFRpKqlXtVXrIE0yXg2NoGXAro4_XDTwkrep2c",
                "url" => "http://weixin.qq.com",
                "miniprogram" => [
                    "appid" => Yii::$app->params['mini']['wxAppId'],
                    "pagepath" => "shopPage/shoppages/index/index"
                ],
                "data" => [
                    "keyword1" => [//订单编号
                        "value" => $out_trade_no,
                    ],
                    "keyword2" => [//退款状态
                        "value" => $status,
                    ],
                    "keyword3" => [//退款金额
                        "value" => $amount,
                    ],
                    "keyword4" => [// 备注
                        "value" => $remarks,
                    ],
                    "keyword5" => [//商品详情
                        "value" => $product
                    ],
                ]
            ]
        ];
         * */
    }
}